/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DB;

import java.io.IOException;
import org.basex.core.BaseXException;
import org.basex.core.Context;
import org.basex.data.Result;
import org.basex.query.QueryProcessor;


/**
 *
 * @author jose
 */
public class DBacess {

    static final Context context = new Context();
    public static void updateFile(String newxml,String filename) throws IOException{
        BaseXClient session = new BaseXClient("localhost", 1984, "admin", "admin");   
        session.execute("OPEN BD");
        session.execute("DELETE "+filename);
        session.execute("ADD "+newxml);
        session.execute("RENAME BD.xml "+filename);
        session.close();
    }
    public DBacess() {
    }
    public static void addFile(String xml,String filename) throws BaseXException, IOException{
       BaseXClient session = new BaseXClient("localhost", 1984, "admin", "admin");   
       session.execute("OPEN BD");
       session.execute("ADD "+xml);
       session.execute("RENAME BD.xml "+filename+".xml");
       
       session.close();
       }
    public static Result executeQuery(String query) {
        try {
            QueryProcessor proc = new QueryProcessor(query, context);
            return proc.execute();
        } catch (Exception e) {
            System.out.println(e);
        }
        return null;
    }
}
